package com.example.springbootusecase.weComNotice;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author Think
 */
@RestController
@Slf4j
public class WeComNotice {
    public static void main(String[] args) {
        //从机器人那边获取的webhook地址
        String dlWeComUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cadcb2be-55e4-41df-9199-ae923a994060";
        WechatMessageDto req =
                WechatMessageDto.builder()
                        .msgtype("text")
                        .text(WechatMessageDto.WechatMessageText.builder()
                                .content("着火啦")
                                // .mentioned_mobile_list(Joiner.on(",").join(mobiles))
                                .build())
                        .build();
        try {
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(dlWeComUrl);
            String params = JSONUtil.toJsonStr(req);
            httpPost.setEntity(new StringEntity(params, ContentType.APPLICATION_JSON));
            httpClient.execute(httpPost);
        }catch (Exception e){
            log.error("企业微信通知执行失败,e:{}",e);
        }
        //冒泡排序demo
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int i : arr) {
            System.out.println(i);
        }

        List<String> list = Arrays.asList("1", "2", "3", "1", "5", "6", "2", "8", "9", "10");
        //集合去重
        Set<String> set = new HashSet<>(list);
        ArrayList<String> list1 = new ArrayList<>(set);
        System.out.println(list1);


    }

}
